﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace boat
{
    class Utils
    {
        static int BoatNum = 3662;
        static public  Boat[] ReadBoatDataFromFile()
        {
            Boat[] boats = new Boat[BoatNum];
            string[] csvLines = new string[12];
            StreamReader r = new StreamReader("boat_data.csv");
            string line = null;
            int lineNum = 0;
            while ( (line = r.ReadLine()) != null)
            {
                csvLines[lineNum] = line;
                lineNum++;
                if (lineNum >= 12)
                    break;
            }

            string[] IDs =csvLines[0].Split(',');
            string[] tons = csvLines[1].Split(',');
            string[] lengths = csvLines[2].Split(',');
            string[] dewaterIntervals = csvLines[3].Split(',');
            string[] BoatEnterIntervals = csvLines[4].Split(',');
            string[] BoatTypes = csvLines[5].Split(',');
            string[] LoadingTimeWithTwoEquipments = csvLines[6].Split(',');
            for (int i = 0; i < BoatNum; ++i)
            {
                Boat boat = new Boat();
                boat.ID = IDs[i];
                boat.Tons = (int)Double.Parse( tons[i] );
                boat.Length = Int32.Parse( lengths[i]);
                boat.TradeType = BoatTypes[i].Equals("0") ? BoatTradeType.eForignTrade : BoatTradeType.eHomeTrade;
                boat.boatType = Double.Parse(tons[i]) >= 5.2 ? BoatType.A : (Double.Parse(tons[i]) > 1.7 ? BoatType.B : BoatType.C);
                boat.BoatEnterHours = double.Parse(BoatEnterIntervals[i]);
                boats[i] = boat;
            }

            return boats;
        }

        static public Boat[] RandomGetBoats( int num)
        {
            Boat[] AllBoats = ReadBoatDataFromFile();
            Boat[] boats = new Boat[num];

            Random r = new Random();

            for (int i = 0; i < num; ++i)
            {
                int index = r.Next(0, BoatNum - 1);
                boats[i] = AllBoats[index];
            }

            return boats;
        }

    }
}
